﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Agents.Agent
{
    //this is the page that is displayed when the agent arrives at the clients address.
    //this is when they discuss and diside whether or not to make an order
    public partial class WithCustomer : System.Web.UI.Page
    {
        #region Data Members
        private Clients client;
        #endregion

        #region Event Handlers

        /// <summary>
        /// Occurs when the page is loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get the client details
            Queries queries = new Queries();
            client = queries.GetClient(Int32.Parse(Request.QueryString["clientId"]));

            //this button is for submiting a reason for not making an order.
            //if the agent clicks the "no order" button, a text box for discribing 
            //a reason will apear- then this butto will be activated
            okBtn.Visible = false;
        }

        //function is activated if the "ok" button is pressed for "no order"
        protected void okBtn_Click(object sender, EventArgs e)
        {
            Queries queries = new Queries();
            Agents agent = queries.GetAgentByUserName(Page.User.Identity.Name);
            queries.ChangeToActive(agent);

            // Add to the agent's log that he left the client
            queries.AgentLeftClient(agent, "סיים ללא הזמנה אצל " +
                client.Name + ". סיבה: " + reasonTxbox.Text);

            Response.Redirect("~/Agent/AgentMenu.aspx");
        }

        //function is activated if the "no order" button is pressed
        protected void endOrderBtn_Click(object sender, EventArgs e)
        {
            //reason box will apear
            reasonTxbox.Visible = true;
            okBtn.Visible = true;
        }

        //for redirecting the agent to the create order page.
        protected void createOrderBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("CreateOrder.aspx?clientId=" + Request.QueryString["clientId"]);
        }

        //for redirecting the agent back
        protected void backBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("StartShiftDisplay.aspx?clientId=" + Request.QueryString["clientId"]);
        }

        #endregion
    }
}
